// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class AUTHORIZATION_CONTACT_REF_I12 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("6 AUT",6)]
  	    [HL7Field(HL7Version.v231, 6, HL7Repeat.False, HL7Required.True,"AUT")]
	    public AUT AUT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("8 CTD",8)]
  	    [HL7Field(HL7Version.v231, 8, HL7Repeat.False, HL7Required.False,"CTD")]
	    public CTD CTD {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			AUT = PopSegmentParseAndCheckRequired<AUT>(availableData, options, "AUT");
			CTD = PopSegmentParseAndCheckRequired<CTD>(availableData, options, "CTD");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isAUT = availableData.StartsWith("AUT", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("AUT", options.Version) || isAUT) {
				return isAUT;
			}
			bool isCTD = availableData.StartsWith("CTD", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CTD", options.Version) || isCTD) {
				return isCTD;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "AUTHORIZATION_CONTACT";
			}
        }

        static AUTHORIZATION_CONTACT_REF_I12() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(AUTHORIZATION_CONTACT_REF_I12));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (AUT != null) {
			string segmentValue = AUT.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (CTD != null) {
			string segmentValue = CTD.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

